<% button_classes = "button button__lg button__secondary w-full" %>

<% unless proposal.rejected? || proposal.withdrawn? %>
  <% if component_settings.participatory_texts_enabled? && from_proposals_list %>
    <%= render partial: "decidim/proposals/proposals/participatory_texts/proposal_vote_button", locals: { proposal:, from_proposals_list: true } %>
  <% else %>
    <div id="proposal-<%= proposal.id %>-vote-button" class="card__proposals-votes-container">
      <% if !current_user %>
        <% if current_settings.votes_blocked? %>
          <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list:), resource: proposal, class: button_classes, data: { "proposal-vote-button": true }, disabled: true do %>
            <%= t("decidim.proposals.proposals.vote_button.votes_blocked") %>
          <% end %>
        <% else %>
          <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list:), resource: proposal, class: button_classes, data: { "proposal-vote-button": true, "redirect-url": proposal_path(proposal) } do %>
            <%= t("decidim.proposals.proposals.vote_button.vote") %>
            <span class="sr-only"><%= decidim_html_escape(present(proposal).title) %></span>
          <% end %>
        <% end %>
      <% else %>
        <% if proposal_voted_by_user?(proposal) %>
          <%= action_authorized_button_to(
            :vote,
            proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list:),
            resource: proposal,
            method: :delete,
            remote: true,
            data: {
              original: t("decidim.proposals.proposals.vote_button.already_voted"),
              replace: t("decidim.proposals.proposals.vote_button.already_voted_hover"),
              "proposal-vote-button": true,
              "redirect-url": proposal_path(proposal)
            },
            disabled: current_settings.votes_blocked?,
            class: "#{button_classes}",
            id: "vote_button-#{proposal.id}"
          ) do %>
            <%= t("decidim.proposals.proposals.vote_button.already_voted") %>
            <%= icon "check-line", class: "already-voted-icon" %>
            <span class="sr-only"><%= decidim_html_escape(present(proposal).title) %></span>
          <% end %>
        <% else %>
          <% if proposal.maximum_votes_reached? && !proposal.can_accumulate_votes_beyond_threshold && current_component.participatory_space.can_participate?(current_user) %>
            <%= content_tag :button, t("decidim.proposals.proposals.vote_button.maximum_votes_reached"), class: button_classes, data: { "proposal-vote-button": true }, disabled: true %>
          <% else %>
            <% if vote_limit_enabled? && remaining_votes_count_for_user == 0 %>
              <%= content_tag :button, t("decidim.proposals.proposals.vote_button.no_votes_remaining"), class: button_classes, data: { "proposal-vote-button": true }, disabled: true %>
            <% elsif current_settings.votes_blocked? || !current_component.participatory_space.can_participate?(current_user) %>
              <%= content_tag :button, t("decidim.proposals.proposals.vote_button.votes_blocked"), class: button_classes, data: { "proposal-vote-button": true }, disabled: true %>
            <% else %>
             <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: proposal, from_proposals_list:), resource: proposal, remote: true, data: { "proposal-vote-button": true, "redirect-url": proposal_path(proposal) }, class: button_classes do %>
                <%= t("decidim.proposals.proposals.vote_button.vote") %>
                <span class="sr-only"><%= decidim_html_escape(present(proposal).title) %></span>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>
    </div>
  <% end %>
<% end %>
